﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace anyfm
{
    public partial class main : Form
    {
        private Button Db = new Button();
        private Form aboutBox = new about();
        public main()
        {
            InitializeComponent();
        }

        private void main_Load(object sender, EventArgs e)
        {
            //Db.Name = "Dy_Button"; //设定名称
            //Db.Location = new Point(100,200);//设定位置
            //splitContainer1.Panel1.Controls.Add(Db);
            //Db.BringToFront();
            //this.ResumeLayout(false);


            mainBrowser.Navigate("http://douban.fm");
            this.Text = "Any FM - douban FM";
            this.notifyIcon.Text = "Any FM - douban FM";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            mainBrowser.Navigate("http://fm.mp3.baidu.com/#/channel/suibiantingting/");
            this.Text = "Any FM - Baidu FM";
            this.notifyIcon.Text = "Any FM - Baidu FM";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            mainBrowser.Navigate("http://douban.fm");
            this.Text = "Any FM - douban FM";
            this.notifyIcon.Text = "Any FM - douban FM";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            mainBrowser.Navigate("http://www.1g1g.com");
            this.Text = "Any FM - 1g1g.com";
            this.notifyIcon.Text = "Any FM - 1g1g.com";
        }

        private void main_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true ;
            toggleMainForm();
        }

        private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                toggleMainForm();
            }
        }

        private void toggleMainForm()
        {
            if (this.Visible == false)
            {
                this.notifyIcon.Visible = true;
                this.Show();
                this.TopMost = true;
                this.Focus();
                this.BringToFront();
                this.TopMost = false;
                this.WindowState = FormWindowState.Maximized;
            }
            else
            {
                this.ShowInTaskbar = false;
                this.notifyIcon.Visible = true;
                this.Hide();
                if (Properties.Settings.Default.ICON_TRAY_SHOW_MESSAGE)
                {
                    this.notifyIcon.ShowBalloonTip(1000, "提示", "Any FM 已经被缩小到这里", ToolTipIcon.Info);
                    Properties.Settings.Default.ICON_TRAY_SHOW_MESSAGE = false;
                    Properties.Settings.Default.Save();
                }
            }
        }

        private void main_Resize(object sender, EventArgs e)
        {

            if (WindowState == FormWindowState.Minimized)
            {
                this.Hide();
            }

        }

/*        private void buttonSwitcher_Click(object sender, EventArgs e)
        {
            if (buttonSwitcher.Text == "<")
            {
                buttonSwitcher.Text = ">";
                //splitContainer1.SplitterDistance = 10;
                splitContainer1.Panel1Collapsed = true;
            }
            else
            {
                buttonSwitcher.Text = "<";
                splitContainer1.Panel1Collapsed = false;
                //splitContainer1.SplitterDistance = 250;
                //splitContainer2.Panel1Collapsed = false;
            }
        }*/

        private void menuQuit_Click(object sender, EventArgs e)
        {
            this.notifyIcon.Visible = false;
            Environment.Exit(0);
        }

        private void menuAbout_Click(object sender, EventArgs e)
        {
            if (aboutBox.Visible == false)
            {
                aboutBox.ShowDialog(this);
            }
            else
            {
                aboutBox.Show();
                aboutBox.WindowState = FormWindowState.Normal;
                aboutBox.TopMost = true;
                aboutBox.Focus();
                aboutBox.BringToFront();
                aboutBox.TopMost = false;
            }
        }

    }
}
